/** 自定义发票查询
* @copyright digitalChina 2017
* @author renzya
* @date 2017-05-11
* 修改人
* 修改日期
* 修改内容
*/

var mysearch = window.location.search;
var arg_lis = mysearch.split('&');
var my_swjg_dm, my_jcdm;
// console.log("search===" + arg_lis);
for (i = 0; i < arg_lis.length; i++) {
    var value = arg_lis[i].split('=')
    if ($.inArray('swjg_dm',value) != -1) {
        my_swjg_dm = value[1]
    }
    if ($.inArray('jcdm',value)  != -1) {
        my_jcdm = value[1]
    }
}

//数据源链接名
var dataSource = "xcdw_app";
//gpm.jcdm = parseInt("{jcdm}") + 1;
//gpm.zbdw.swjg_dm = "{swjg_dm}";// result 页面制表单位只需要使用 parent.gpm.zbdw.swjg_mc 即可
gpm.jcdm = my_jcdm ? my_jcdm :"{jcdm}";
gpm.zbdw.swjg_dm = my_swjg_dm ? my_swjg_dm : "{swjg_dm}";

// 要跳转的result页路径
//var url = "/reports/adp/cx/sbzs/tdsfqktjb/top_result.fpd";
var url = Request.QueryString["objpath"].replace(/top.fpd/,"top_result.fpd")+"&t="+Math.random();

/**
 * 配置分组项目
 * @type {Array}
 */
var array_dynamicClo = [
    //"ZGSWSKFJ_DM",
    //"HYML_DM"
    //"DJZCLX_DM",
    //"JDXZ_DM",
    //"TDSFYYLX_DM",
    //"SSGLY_DM"
];
/**
 * 配置分组项目中需要下钻的列
 */
var isXz = {
    //ZGSWSKFJ_DM: true,
    //HYML_DM: true//
    //DJZCLX_DM: true,
}
/**
 * 配置下钻路径。需要下钻的仅有 税务机关、行业、登记注册类型需要配置路径
 * 其他仅需要配置为其本身字段名即可。如：JDXZ_DM
 * 此处会引起歧义的字段列建议带上 别名。如：J.JDXZ_DM
 * @type {Object}
 */
var xzPath = {
    //与分组项目中的ID要保持一致
    //"ZGSWSKFJ_DM": new Array("S.swjg_1_dm", "S.swjg_2_dm", "S.swjg_3_dm", "S.swjg_4_dm", "S.swjg_5_dm"),
    //"HYML_DM": new Array("H.hyml_dm", "H.hydl_dm", "H.hyzl_dm", "H.hy_dm")
    //"DJZCLX_DM": new Array("D.djzclxdl_dm", "D.djzclxzl_dm", "D.djzclx_dm"),
    //"JDXZ_DM":new Array("J.JDXZ_DM"),
    //"TDSFYYLX_DM":new Array("TDSFYYLX_DM"),
    //"SSGLY_DM":new Array("SSGLY_DM")
};
//若当前登录税务机关为浙江地税，可以下钻到第六级次。
if(gpm.zbdw.swjg_dm.substr(0,3)=="233"){
  xzPath.ZGSWSKFJ_DM.push("S.swjg_6_dm")
}
/**
 * 若有行业及登记注册类型下钻，则配置下方初始下钻序号。
 * 下钻序号对应上方 xzPath.其他不需要配置
 * @type {Number}
 */
gpm.xh.DJZCLX_DM = 0; //初始化下钻序号
gpm.xh.HYML_DM = 0; //初始化下钻序号

//配置需要转码的列
//征收项目： ZSXM_DM:zsxm
//征收品目： ZSPM_DM:zspm
gpm.zmCol = {
    ZGSWSKFJ_DM: "swjg"
    //HYML_DM: "hy"
    //DJZCLX_DM: "djzclx",
    //TDSFYYLX_DM:"tdsfyylx",
    //JDXZ_DM:"jdxz",
    //SSGLY_DM:"swry"
}

/**
 * 异步加载控件
 */
function initComponentsByAjax(){
    debugger
      // 自动生成部分公共组件
    autoCompletControl(gpm.jcdm, gpm.zbdw.swjg_dm);

	// 预警阈值


    // 统计时间起

    var jdqNodes = [
        {id:'03',pId:0,name:'第一季度',checked:true},
        {id:'06',pId:0,name:'第二季度'},
        {id:'09',pId:0,name:'第三季度'},
        {id:'12',pId:0,name:'第四季度'}
    ];
    initIdivRadioAjax("divcon_jdq","",dataSource,jdqNodes);

    // 统计时间止

    var jdzNodes = [
        {id:'03',pId:0,name:'第一季度',checked:true},
        {id:'06',pId:0,name:'第二季度'},
        {id:'09',pId:0,name:'第三季度'},
        {id:'12',pId:0,name:'第四季度'}
    ];
    initIdivRadioAjax("divcon_jdz","",dataSource,jdzNodes);



    // var fzxmNodes = [{id:'ZGSWSKFJ_DM',pId:0,name:'税务机关',checked:true},
    //                    {id:'HYML_DM',pId:0,name:'行业'}];
    //                    //{id:'DJZCLX_DM',pId:0,name:'登记注册类型'},
    //                    //{id:'JDXZ_DM',pId:0,name:'街道乡镇'},
    //                    //{id:'TDSFYYLX_DM',pId:0,name:'退抵税费原因类型'},
    //                    //{id:'SSGLY_DM',pId:0,name:'税收管理员'}
    // initIdivTreeAjax("divcon_fzxm","",dataSource,fzxmNodes);

}

//控制控件级联
function modifyinit(id,Idiv) {
    debugger;
    // 街道乡镇、税务人员的级联
    modifyInitSwryAndJdxz(id, Idiv, gpm.jcdm);
}
/* getQyInfo();
function getQyInfo(){
    debugger;
    var getUUIDSql = "SELECT * FROM XCDW_DIM.DIM_XZQH_QG WHERE XZQHSZ_DM = '000000'";
    var result = getfpdjson(getUUIDSql);
    gpm.cxtj.uuid  = result[0].UUID;
} */

//获取参数控件中的值
function interface_getQueryCon() {

    debugger;


    //var djcsrqq = document.getElementById("djcsrqq").value.replace(/\-/g, "");
    //var djcsrqz = document.getElementById("djcsrqz").value.replace(/\-/g, "");
    if(!document.getElementById("datetimeq").value){
          alert ("统计月份起为必选条件，请选择!");
          return  false;
    }
    if(!document.getElementById("datetimez").value){
           alert ("统计月份止为必选条件，请选择!");
           return  false;
    }
    /* if(djcsrqq > djcsrqz && djcsrqz != ''){
         alert("多缴产生日期起不能大于多缴产生日期止！")
         return false;
    } */

    gpm.cxtj.params = "";
    gpm.cxtj.str_where = "";
    gpm.cxtj.skssqz = "";
    gpm.cxtj.djcsrqz = "";
    //开票日期起
	var jd_obj = {"03":'第一季度',"06":'第二季度',"09":'第三季度',"12":'第四季度'}
    if (document.getElementById("datetimeq")) {
        var yearq = document.getElementById("datetimeq").value;
		var jdq = getIdivTreeValue("divcon_jdq");
		var jdq_mc = jd_obj[jdq];
        //var yearq = dtq.substr(0, 4);
        //var monthq = dtq.substr(5, 2);
        //gpm.cxtj.rq_q = yearq + monthq + "01";//放在单独的属性里面
        gpm.cxtj.rq_q = yearq + jdq;
        gpm.zbdw.tjrq = yearq +"年"+ jdq_mc;
        //gpm.cxtj.params += "rq_q==" + yearq + monthq + "01";//此params用作链接清册时传参用
    }

    //开票日期止
    if (document.getElementById("datetimez")) {
        var yearz = document.getElementById("datetimez").value;
		var jdz = getIdivTreeValue("divcon_jdz");
        //var yearz = dtz.substr(0, 4);
        //var monthz = dtz.substr(5, 2);
        //gpm.cxtj.year = yearz;
        //gpm.cxtj.month = monthz;
        //gpm.cxtj.rq_z = yearz + monthz +"01";
        gpm.cxtj.rq_z = yearz + jdz;
		var jdz_mc = jd_obj[jdz];
        gpm.zbdw.tjrq += " 至 "+yearz +"年"+ jdz_mc ;
        //gpm.cxtj.params += "@@rq_z==" + yearz + monthz + "01";
    }
	if(gpm.cxtj.rq_q > gpm.cxtj.rq_z){
		alert('时间范围输入错误');
		return false;
	}
	//alert('===' + gpm.zbdw.tjrq)
    if(gpm.zbdw.swjg_dm.substr(0,3) == "233"){
        //税务机关
        if(getIdivTreeValue("divcon_swjg").length > 0){
               var swjg_dm = "";
               swjg_dm = document.getElementById("Idivcon_swjg").name;

               gpm.cxtj.ZGSWSKFJ_DM = swjg_dm;
               gpm.cxtj.params +="@@ZGSWSKFJ_DM==" + swjg_dm;
               //对于非必选的条件，只有当有值时才拼接条件
               gpm.cxtj.str_where += "  AND (SWJG_1_DM IN ('"+swjg_dm+"') OR SWJG_2_DM IN ('"+swjg_dm+"') OR SWJG_3_DM IN     ('"+swjg_dm+"') OR"
                                    + "    SWJG_4_DM IN ('"+swjg_dm+"') OR SWJG_5_DM IN ('"+swjg_dm+"') OR SWJG_6_DM IN ('"+swjg_dm+"'))";
        }else{
              // 增加权限税务机关过滤
              gpm.cxtj.str_where += " and s.swjg_"+gpm.jcdm+"_dm = '"+gpm.zbdw.swjg_dm+ "'" ;
        }
    }else{
        //税务机关
        if(getIdivTreeValue("divcon_swjg").length > 0){
               var swjg_dm = "";
               swjg_dm = document.getElementById("Idivcon_swjg").name;
               swjg1_dm = getIdivTreeValue("divcon_swjg");
               gpm.cxtj.ZGSWSKFJ_DM = swjg_dm;
               gpm.cxtj.params +="@@ZGSWSKFJ_DM==" + swjg_dm;
               //对于非必选的条件，只有当有值时才拼接条件
               gpm.cxtj.str_where += "  AND (SWJG_1_DM IN ('"+swjg_dm+"') OR SWJG_2_DM IN ('"+swjg_dm+"') OR SWJG_3_DM IN     ('"+swjg_dm+"') OR"
                                    + "    SWJG_4_DM IN ('"+swjg_dm+"') OR SWJG_5_DM IN ('"+swjg_dm+"'))";
        }else{
              // 增加权限税务机关过滤
              gpm.cxtj.str_where += " and s.swjg_"+gpm.jcdm+"_dm = '"+gpm.zbdw.swjg_dm+ "'" ;
        }
    }
/*
    //税务机关
    if(getIdivTreeValue("divcon_swjg").length > 0){
           var swjg_dm = "";
           swjg_dm = getIdivTreeValue("divcon_swjg");

           gpm.cxtj.ZGSWSKFJ_DM = swjg_dm;
           gpm.cxtj.params +="@@ZGSWSKFJ_DM==" + swjg_dm;
           //对于非必选的条件，只有当有值时才拼接条件
           gpm.cxtj.str_where += "  AND (SWJG_1_DM IN ('"+swjg_dm+"') OR SWJG_2_DM IN ('"+swjg_dm+"') OR SWJG_3_DM IN ('"+swjg_dm+"') OR"
                                + "    SWJG_4_DM IN ('"+swjg_dm+"') OR SWJG_5_DM IN ('"+swjg_dm+"'))";
    }else{
          // 增加权限税务机关过滤
          gpm.cxtj.str_where += " and s.swjg_"+"{jcdm}"+"_dm = '"+"{swjg_dm}'" ;
    }
*/
    //登记注册类型
    /* if(getIdivTreeValue("divcon_djzclx").length > 0){
           var djzclx_dm = "";
           var djzclxWhere =["d.djzclxdl_dm","d.djzclxzl_dm","d.djzclx_dm"];
            if(!(getIdivTreeValue("divcon_djzclx"))){
               gpm.cxtj.djzclx = " and 'all' = 'all'";
           }else{
               var djzclxConditon = getIdivTreeValue("divcon_djzclx").split("','");
               for( i= 0;i<djzclxConditon.length;i++){
                   djzclxConditon[i] = djzclxWhere[djzclxConditon[i].substr(3,1)] + " = '" +djzclxConditon[i].substr(0,3)+"'";
               }
               djzclx_dm = djzclxConditon.join(") or (");
               gpm.cxtj.str_where  += "and (("+djzclx_dm+" ))";

            }
    } */

    //预警阈值-工业
    gpm.cxtj.yjfz_gy = "";
    if($("#txt_yjfz_gy").val().length>0){
        var yjfz_gy = "";
        yjfz_gy = $("#txt_yjfz_gy").val();
		gpm.cxtj.yjfz_gy = yjfz_gy;
        //gpm.cxtj.je= " and ABS(A.CYJE) >= "+je;
    }

    //预警阈值-商业
    gpm.cxtj.yjfz_sy = "";
    if($("#txt_yjfz_sy").val().length>0){
        var yjfz_sy = "";
        yjfz_sy = $("#txt_yjfz_sy").val();
		gpm.cxtj.yjfz_sy = yjfz_sy;
        //gpm.cxtj.je= " and ABS(A.CYJE) >= "+je;
    }


    // gpm.cxtj.swjg_mc = $("#lbl_swjg_mc").html();
    //alert(gpm.cxtj.str_where);
    return true;
}

/* 页面加载函数
* @param
* @return
*/
function fpd_onload(){
  //initDate();//初始化日期起为当年第一月。若只有一个日期，需要注释此句
  //将页面上的默认值控件暂存起来。重置时取出
  gpm.csh.rq_q = $("#datetimeq").val();
  gpm.csh.rq_z = $("#datetimez").val();
  gpm.csh.jdq = $("#divcon_jdq").val();
  gpm.csh.jdz = $("#divcon_jdz").val();
  gpm.csh.swjg = $("#divcon_swjg").val();
  gpm.csh.yjyz_gy = $("#txt_yjfz_gy").val();
  gpm.csh.yjyz_sy = $("#txt_yjfz_sy").val();
	debugger;
    //页面端注册init函数，解决跨域调用数据问题
    interface_para_init();
}
/**
 * 重置按钮事件
 */
function reset(){
  $("#datetimeq").val(gpm.csh.rq_q);
  $("#datetimez").val(gpm.csh.rq_z);
  $("#divcon_jdq").val(gpm.csh.jdq);
  $("#divcon_jdz").val(gpm.csh.jdz);
  $("#divcon_swjg").val(gpm.csh.swjg);
  $("#txt_yjfz_gy").attr("value",gpm.csh.yjyz_gy);
  $("#txt_yjfz_sy").attr("value",gpm.csh.yjyz_sy);

  initComponentsByAjax();//初始化所有zTree生成的树
}



